local skill = fk.CreateSkill{
  name = "iberia__qiaobian"
}

Fk:loadTranslationTable{
  [skill.name] = "巧变",
  [":"..skill.name] = "每回合限一次，当你摸牌时，你可以改为移动场上的一张牌。",
  [skill.name.."-prompt"] = "巧变：你将摸%arg张牌，可以改为移动场上的一张牌"
}

skill:addEffect(fk.BeforeCardsMove, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skill.name) and player:usedSkillTimes(skill.name, Player.HistoryTurn) == 0 then
      for _, move in ipairs(data) do
        if move.to == player and move.moveReason == fk.ReasonDraw then
          if #move.moveInfo > 0 then
            event:setCostData(self, #move.moveInfo)
            return true
          end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askToChooseToMoveCardInBoard(player, {
      skill_name = skill.name,
      cancelable = true,
      prompt = skill.name.. "-prompt:::"..event:getCostData(self),
    })
    if #tos == 2 then
      event:setCostData(self, tos)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self)
    if tos then
      player.room:askToMoveCardInBoard(player, {
        target_one = tos[1],
        target_two = tos[2],
        skill_name = skill.name,
      })
    end
    if player:isAlive() then
      return true
    end
  end,
})

return skill
